home *** CD-ROM | disk | FTP | other *** search
/ PCMania 73 / PCMania CD73_1.iso / pcmania / virus73 / ANTIASTR.C next >
C/C++ Source or Header  |  1998-08-19  |  13KB  |  370 lines

  1. /*----------------------------------------------*/
  2. /* ANTI-ASTRA (c) 1998 Por Javier Guerrero Díaz 
  3. /* Busca en memoria y en archivos el virus ASTRA.521.
  4. /*
  5. /* La sintaxis es: ANTIASTR [directorio] </a>.
  6. /* El programa buscará el virus en todos los
  7. /* archivos contenidos en el directorio especificado.
  8. /* Programado con Borland C++ 5.02
  9. /*----------------------------------------------*/
  10. /*      Javier Guerrero Díaz     */
  11. /*      email: jgd@redestb.es    */
  12. /*-------------------------------*/
  13.  
  14. #include <stdio.h>
  15. #include <dos.h>
  16. #include <dir.h>
  17. #include <conio.h>
  18. #include <bios.h>
  19. #include <stdlib.h>
  20. #include <direct.h>
  21. #include <io.h>
  22.  
  23. void fin(void);
  24. void mal(void);
  25. void intro(void);
  26. void buscafichero(void);
  27. void panta(void);
  28. void obtieneinfo(void);
  29. void buscamem(void);
  30. void busca(void);
  31. void mensaje(char *mensa);
  32. void encontrado(void);
  33. void matavir(void);
  34. void elige(void);
  35. void analiza(void);
  36.  
  37. #define LOWORD(l)           ((unsigned int)(l))
  38. #define HIWORD(l)           ((unsigned int)(((unsigned long)(l) >> 16) & 0xFFFF))
  39. #define LOBYTE(w)           ((unsigned char)(w))
  40. #define HIBYTE(w)           ((unsigned char)(((unsigned short)(w) >> 8) & 0xFF))
  41.  
  42. union REGS registros;
  43. char tecla,diractual[50],dirdestino[50];
  44. int temp,infec=0,analiz=0,segmento;
  45. unsigned long memlibre=0;
  46. FILE *fichero;
  47. struct ffblk arch;
  48. struct date fecha;
  49. struct dostime_t hora;
  50. char cadena[]={ 0x3D,0x05,0xFF,0x75,0x04,0xB8,0xFF,0x05,0xCF,0x80,
  51.         0xFC,0x09,0x75,0x1D,0x50,0x52,0x1E,0x33 };
  52. char flag;
  53. int far *direcc;
  54. unsigned long int salto,offset;
  55. int rut_int_org;
  56. char orgbyt[3];
  57.  
  58. #pragma argsused
  59. void main(argc,argv)
  60. int argc;
  61. char *argv[];
  62. {
  63. if (*argv[1]==NULL || *argv[1]=='?') 
  64.         { printf("\nANTIASTR (c)1998 Por Javier Guerrero Díaz\n");
  65.               printf("Sintaxis: ANTIASTR [directorio] </a>\n"); exit(-1);}
  66. if (argv[2][0]=='/' && argv[2][1]=='A') flag='a';
  67. else if (argv[2][0]=='/' && argv[2][1]=='a') flag='a';
  68. else flag=NULL;
  69.  
  70. getcwd(diractual,50);
  71. _setcursortype(_NOCURSOR);
  72.  
  73. if (chdir(argv[1])==-1) { printf("\nError. No puedo acceder al directorio ");
  74.             printf("%s.\n",argv[1]); mal(); }
  75. getcwd(dirdestino,50);
  76. intro();
  77. panta();
  78. buscamem();
  79. fin();
  80. }
  81.  
  82. void matavir(void)
  83. {
  84. int res,handle;
  85. unsigned long tamanoreal;
  86.  
  87. tamanoreal=arch.ff_fsize-521;
  88. res=fseek(fichero,8,SEEK_SET);
  89.     if (res!=0) { 
  90.              mensaje("Error gestionando fichero!."); mal();
  91.             }
  92. res=putw(rut_int_org,fichero);
  93.     if (res!=rut_int_org) { 
  94.              mensaje("Error escribiendo en archivo!."); mal(); 
  95.             }
  96. handle=fileno(fichero); res=chsize(handle,tamanoreal);
  97. if (res!=0) { 
  98.          mensaje("Error al modificar el tamaño del archivo."); mal();
  99.         }
  100. if (flag!='a')
  101.     {
  102.      mensaje("OK!. Virus eliminado del fichero.");
  103.     }
  104. else
  105.     {
  106.      window(1,1,80,25); textattr(WHITE|BLUE<<4); gotoxy(24,23);
  107.      cprintf("                                                  ");
  108.      gotoxy(24,23); cprintf("OK!. Virus eliminado del fichero.");
  109.      sleep(1); gotoxy(24,23);
  110.      cprintf("                                                  ");                 
  111.     }
  112. }
  113.  
  114. void analiza(void)
  115. {
  116. int res,rut_int;
  117. char buffer[18];
  118.  
  119. res=getw(fichero); 
  120. if (res!=0xFFFF) goto sale;
  121. res=fseek(fichero,8,SEEK_SET);
  122.     if (res!=0) { 
  123.              mensaje("Error gestionando fichero!."); mal();
  124.             }
  125. rut_int=getw(fichero);
  126. rut_int+=0x79;
  127. res=fseek(fichero,rut_int,SEEK_SET);
  128.     if (res!=0) { 
  129.              mensaje("Error gestionando fichero!."); mal();
  130.             }
  131. rut_int_org=getw(fichero);
  132. rut_int+=0x15;
  133. res=fseek(fichero,rut_int,SEEK_SET);
  134.     if (res!=0) { 
  135.              mensaje("Error gestionando fichero!."); mal();
  136.             }
  137.  
  138. res=fread(buffer,1,18,fichero);
  139.     if (res!=18) { 
  140.              mensaje("Error leyendo archivo!."); mal();
  141.             }
  142. for (res=1;res<18;res++)
  143.     {
  144.      if (cadena[res]!=buffer[res]) goto sale;
  145.     }
  146.     encontrado();
  147. sale:
  148. }
  149.  
  150. void encontrado(void)
  151. {
  152. window(22,8,57,20);infec++;
  153. textattr(WHITE|RED<<4);
  154. cprintf("╔═══════════╦══════════╦═══════════╗");
  155. cprintf("║           ║ ATENCION ║           ║");
  156. cprintf("║           ╚══════════╝           ║");
  157. cprintf("║                                  ║");
  158. cprintf("║                                  ║");
  159. cprintf("║                                  ║");
  160. cprintf("║                                  ║");
  161. cprintf("║                                  ║");
  162. if (flag!='a'){
  163. cprintf("║ PULSE LA TECLA 'SUPR' PARA MATAR ║");
  164. cprintf("║  EL VIRUS O CUALQUIER OTRA PARA  ║");
  165. cprintf("║      IGNORAR ESTE FICHERO.       ║");
  166. cprintf("╚══════════════════════════════════╝");}
  167. else {
  168. cprintf("║ ATENCION: EL MODO AUTOMATICO HA  ║");
  169. cprintf("║  SIDO ACTIVADO. EL FICHERO SERA  ║");
  170. cprintf("║   DESINFECTADO AUTOMATICAMENTE.  ║");
  171. cprintf("╚══════════════════════════════════╝");}
  172. gotoxy(3,5); cprintf("SE DETECTO LA MARCA DE INFECCION");
  173. gotoxy(3,6); cprintf("  PROPIA DEL VIRUS 'ASTRA.521'");
  174. gotoxy(3,7); cprintf("    EN ARCHIVO:");
  175.  
  176. textattr(YELLOW|RED<<4); gotoxy(19,7); cprintf("%-12s",arch.ff_name);
  177. textattr(WHITE|BLUE<<4); window(1,1,80,25);
  178. mensaje("Atención: Fichero infectado por el virus !.");
  179. if (flag!='a') elige(); 
  180. else matavir();
  181. panta(); obtieneinfo();
  182. gotoxy(28,15); cprintf("%-12s",arch.ff_name);
  183. gotoxy(62,15); cprintf("%-8ld",arch.ff_fsize);
  184. gotoxy(33,17); cprintf("%-3d",analiz);
  185. gotoxy(64,17); cprintf("%-3d",infec);
  186. }
  187.  
  188. void elige(void)
  189. {
  190. int res=0;
  191.  
  192. res=bioskey(0);
  193. if (res==0x5300) matavir();
  194. else if (res==0x532E) matavir();
  195. }
  196.  
  197. void buscamem(void)
  198. {
  199. window(18,7,62,11);
  200. textattr(WHITE|BLUE<<4);
  201. cprintf("╔═══════════════════════════════════════════╗");
  202. cprintf("║   Buscando virus: ASTRA.521 en memoria.   ║");
  203. cprintf("║         Analizando la RAM ....            ║");
  204. cprintf("╚═══════════════════════════════════════════╝");
  205. sleep(1);
  206. busca();
  207. }
  208.  
  209. void busca(void)
  210. {
  211. char far *cop;
  212. char dummy;
  213. int segm;
  214.  
  215. direcc=(int far *)MK_FP(0x0000,0x028F);
  216. cop=(char far *)MK_FP(0x0,0x199);
  217. if (*direcc==0xFF05)
  218. {
  219. window(8,6,70,23); textattr(YELLOW|RED<<4); putch(7); 
  220. cprintf("╔═════════════════════════════════════════════════════════════╗");
  221. cprintf("║         Atención: Virus ASTRA.521, detectado en la          ║");
  222. cprintf("║               dirección de memoria : 0000:0200              ║");
  223. cprintf("╟─────────────────────────────────────────────────────────────╢");
  224. cprintf("║                                                             ║");
  225. cprintf("║                                                             ║");
  226. cprintf("║                                                             ║");
  227. cprintf("║                                                             ║");
  228. cprintf("║                                                             ║");
  229. cprintf("║                                                             ║");
  230. cprintf("║                                                             ║");
  231. cprintf("║                                                             ║");
  232. cprintf("║                                                             ║");
  233. cprintf("║                                                             ║");
  234. cprintf("║                                                             ║");
  235. cprintf("╚═════════════════════════════════════════════════════════════╝");
  236. window(9,10,69,21); textattr(WHITE|RED<<4);
  237. for (temp=0;temp<669;temp++) 
  238. { dummy=*cop; if (dummy<32) dummy='.'; cprintf("%c",dummy); cop++; }                    
  239. mensaje("¡ Virus encontrado en memoria !"); textattr(LIGHTGRAY|BLACK<<4);
  240. sleep(5); clrscr(); panta();
  241. window(17,7,63,15); textattr(WHITE|RED<<4); 
  242. cprintf("╔═════════════════════════════════════════════╗");
  243. cprintf("║  Aviso: El virus se encuentra en memoria.   ║");
  244. cprintf("║ Aunque el programa continuará su ejecucion, ║");
  245. cprintf("║  se recomienda arrancar con un disco limpio ║");
  246. cprintf("║        y ejecutar de nuevo ANTIASTR.        ║");
  247. cprintf("║                                             ║");
  248. cprintf("║                                             ║");
  249. cprintf("╚═════════════════════════════════════════════╝");
  250. sleep(4); textattr(LIGHTGRAY|BLACK<<4); clrscr(); panta(); buscafichero();
  251. }
  252. else { 
  253. window(18,7,62,11); textattr(WHITE|GREEN<<4);
  254. cprintf("╔═══════════════════════════════════════════╗");
  255. cprintf("║   OK !. No se encontró el virus en RAM.   ║");
  256. cprintf("║          Analizando archivos ....         ║");
  257. cprintf("╚═══════════════════════════════════════════╝");
  258. sleep(3); textattr(LIGHTGRAY|BLACK<<4); 
  259. clrscr(); panta(); buscafichero(); }
  260. }
  261.  
  262. void obtieneinfo(void)
  263. {
  264. getdate(&fecha);
  265. _dos_gettime(&hora);
  266. registros.h.ah=0x48; registros.x.bx=0xFFFF;
  267. int86(0x21,®istros,®istros);
  268. memlibre=registros.x.bx; memlibre*=16;
  269. gotoxy(14,11); cprintf("%02d/%02d/%d",fecha.da_day,fecha.da_mon,fecha.da_year);
  270. gotoxy(34,11); cprintf("%02d:%02d:%02d",hora.hour,hora.minute,hora.second);
  271. gotoxy(62,11); cprintf("%ld",memlibre); gotoxy(32,13); cprintf("%s",dirdestino);
  272. }
  273.  
  274. void buscafichero(void)
  275. {
  276. temp=findfirst("*.*",&arch,0);
  277.     while (!temp)
  278.         { obtieneinfo();
  279.     fichero=fopen(arch.ff_name,"r+b");
  280.         if (fichero==NULL) 
  281.         { gotoxy(24,23);
  282.           cprintf("                                                  ");
  283.           gotoxy(24,23); cprintf("Error abriendo fichero!"); putch(7);
  284.           sleep(1); gotoxy(24,23);
  285.           cprintf("                                                  ");                        
  286.         }
  287.         if (arch.ff_fsize<521) goto cierra;
  288.         analiz++;
  289.         gotoxy(28,15);
  290.         cprintf("%-12s",arch.ff_name);
  291.         gotoxy(62,15);
  292.         cprintf("%-8ld",arch.ff_fsize);
  293.         gotoxy(33,17);
  294.         cprintf("%-3d",analiz); 
  295.         gotoxy(64,17);
  296.         cprintf("%-3d",infec);
  297.         analiza();
  298. cierra:         fclose(fichero);
  299.         temp=findnext(&arch);
  300.         }
  301.  
  302. chdir(diractual);       
  303. }
  304.  
  305. void intro(void)
  306. {
  307. clrscr(); gotoxy(20,9); textattr(YELLOW|BLUE<<4);
  308. cprintf("╔═════════════════════════════════════╗\n"); gotoxy(20,10);
  309. cprintf("║             ANTI-ASTRA              ║\n"); gotoxy(20,11);
  310. cprintf("║ (c) 1998  Por Javier Guerrero Diaz. ║\n"); gotoxy(20,12);
  311. cprintf("║ Rastrea los archivos del directorio ║\n"); gotoxy(20,13);
  312. cprintf("║  especificado como parámetro a la   ║\n"); gotoxy(20,14);
  313. cprintf("║    busqueda del virus ASTRA.521.    ║\n"); gotoxy(20,15);
  314. cprintf("╚═════════════════════════════════════╝\n");
  315. textattr(LIGHTGRAY|BLACK<<4);tecla=getch();
  316. clrscr();
  317. }
  318.  
  319. void panta(void)
  320. {
  321. window(20,2,60,7);
  322. gotoxy(1,1);
  323. textattr(YELLOW|BLUE<<4);
  324. cprintf("╔═══════════════════════════════════════╗");
  325. cprintf("║  DETECTOR/VACUNA DEL VIRUS: ASTRA.521 ║");
  326. cprintf("║     (C) Por Javier Guerrero Diaz      ║");
  327. cprintf("╚═══════════════════════════════════════╝");
  328. window(5,8,75,20);
  329. cprintf("╔═════════════════════════════════════════════════════════════════════╗");
  330. cprintf("║                         ANALISIS DE ARCHIVOS                        ║");
  331. cprintf("║                                                                     ║");
  332. cprintf("║ Fecha:               Hora:              Memoria Libre:        bytes ║");
  333. cprintf("║                                                                     ║");
  334. cprintf("║  Directorio de Búsqueda:                                            ║");
  335. cprintf("║                                                                     ║");
  336. cprintf("║  Nombre de Archivo :                 Longitud Archivo:              ║");
  337. cprintf("║                                                                     ║");
  338. cprintf("║      Archivos Analizados:           Archivos Infectados:            ║");
  339. cprintf("║                                                                     ║");
  340. cprintf("╚═════════════════════════════════════════════════════════════════════╝");
  341. window(1,22,80,25);
  342. cprintf("╔══════════════════════════════════════════════════════════════════════════════╗");
  343. cprintf("║ RESULTADO OPERACION:                                                         ║");
  344. cprintf("╚══════════════════════════════════════════════════════════════════════════════╝");
  345. textattr(WHITE|BLUE<<4); window(1,1,80,25);
  346. }
  347.  
  348. void mensaje(mensa)
  349. char mensa[50];
  350. {
  351. window(1,1,80,25); textattr(WHITE|BLUE<<4); gotoxy(24,23);
  352. cprintf("                                                  ");
  353. gotoxy(24,23); cprintf("%s",mensa); putch(7);
  354. /*sleep(1);*/ gotoxy(24,23);
  355. cprintf("                                                  ");                 
  356. }
  357.  
  358. void fin(void)
  359. {
  360. _setcursortype(_NORMALCURSOR); textattr(LIGHTGRAY|BLACK<<4);
  361. exit(0);
  362. }
  363.  
  364. void mal(void)
  365. {
  366. _setcursortype(_NORMALCURSOR); textattr(LIGHTGRAY|BLACK<<4);
  367. printf("\nPrograma finalizado anormalmente.\n");
  368. exit(-1);
  369. }
  370.